package br.org.ifrr.service;

import java.io.Serializable;

import javax.inject.Inject;

import br.org.ifrr.model.Gestor;
import br.org.ifrr.repository.Gestores;
import br.org.ifrr.util.jpa.Transactional;
import br.org.ifrr.util.jsf.service.NegocioException;

public class CadastroGestorService implements Serializable{

	private static final long serialVersionUID = 1L;
	
	@Inject
	private Gestores gestores;
	
	@Transactional
	public Gestor salvar(Gestor gestor){
		
		Gestor gestorExistente = gestores.porNomeSetor(gestor.getSetor()); 
		
		if(gestorExistente != null && !gestorExistente.equals(gestor)){
			throw new NegocioException("Já existe um setor com o nome informado.");
		}
		
		return gestores.guardar(gestor);
	}
		
		
}
